﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AmbiguityByClickWindow : MonoBehaviour
{
    [Range(1, 5)]
    public float speed = 1;

    private bool enableAmbiguity = false;
    private RadialAmbiguityEffect effect;
    private float inMaxValue = 0.001f;

    // Start is called before the first frame update
    void Start()
    {
        effect = this.GetComponent<RadialAmbiguityEffect>();
        effect.intensity = 0;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && effect != null && effect.intensity == 0)
        {
            Vector2 pos = new Vector2(Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height);
            effect.centerPosx = pos.x;
            effect.centerPosy = pos.y;
            effect.intensity = 0;
            enableAmbiguity = true;
        }

        if (enableAmbiguity)
        {
            effect.intensity += Time.deltaTime * inMaxValue * speed;
            if (effect.intensity >= inMaxValue)
            {
                enableAmbiguity = false;
            }
        }
        else if (effect.intensity > 0)
        {
            effect.intensity -= Time.deltaTime * inMaxValue * speed;
            if (effect.intensity <= 0)
            {
                effect.intensity = 0;
            }
        }
    }
}
